package cn.tedu.cwfw.pet.service.impl;

import cn.tedu.cwfw.pet.mapper.PetCateMapper;
import cn.tedu.cwfw.pet.pojo.dto.PetCateSaveParam;
import cn.tedu.cwfw.pet.pojo.entity.PetCategory;
import cn.tedu.cwfw.pet.pojo.vo.PetCategoryVO;
import cn.tedu.cwfw.pet.service.PetCateService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.Date;
import java.util.List;

@Service
@Slf4j
public class PetCateServiceImpl implements PetCateService {
    @Autowired
    private PetCateMapper petCateMapper;

    @Override
    public void insert(PetCateSaveParam petCateSaveParam) {
        log.debug("添加宠物品种信息:{}", petCateSaveParam);
        PetCategory petCategory = new PetCategory();
        BeanUtils.copyProperties(petCateSaveParam, petCategory);
        petCategory.setCreateTime(new Date());
        petCateMapper.insert(petCategory);
        log.debug("添加宠物品种信息成功");
    }

    @Override
    public List<PetCategoryVO> findAll() {
        log.debug("查询所有品种信息");
        List<PetCategoryVO> petCategoryVOS = petCateMapper.findAll();
        return petCategoryVOS;
    }

    @Override
    public List<PetCategoryVO> findByType(Long petType) {
        log.debug("根据类型查询所有品种信息:{}", petType);
        List<PetCategoryVO> petCategoryVOS = petCateMapper.findByType(petType);
        return petCategoryVOS;
    }

    @Override
    public void delete(Long id) {
        log.debug("删除品种信息:{}", id);
        petCateMapper.delete(id);
        log.debug("删除品种信息成功");
    }

    @Override
    public void update(PetCateSaveParam petCateSaveParam) {
        log.debug("修改品种信息:{}", petCateSaveParam);
        PetCategory petCategory = new PetCategory();
        BeanUtils.copyProperties(petCateSaveParam, petCategory);
        petCategory.setUpdateTime(new Date());
        petCateMapper.update(petCategory);
        log.debug("修改品种信息成功");
    }
}
